﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Linq;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LMS.SMSH.BLL;
using LMS.SMSH.MODEL;

namespace LMS.SMSH.WEB
{
    public partial class AdmLabOrder : System.Web.UI.Page
    {
        Int32 rowNo = 0;//行编号


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                /// 绑定gvOrderLab数据
                bindgvOrderLab();
            }
        }

        /// <summary>
        /// 绑定gvOrderLab数据
        /// </summary>
        private void bindgvOrderLab()
        {
            gvOrderLab.DataSource = LMSDataContext.GetLMSDB.sp_viewOrderLab();
            gvOrderLab.DataKeyNames = new string[] { "orderId" };
            gvOrderLab.DataBind();
        }

        /// <summary>
        /// 数据行绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvOrderLab_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                rowNo++;
                e.Row.Cells[0].Text = (gvOrderLab.PageIndex * gvOrderLab.PageSize + rowNo).ToString();
                //鼠标悬停变色     #ffaa11这个颜色不错
                e.Row.Attributes.Add("onmouseover", "oldBG=this.style.backgroundColor;this.style.backgroundColor='#ffbbee';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=oldBG;");

                //删除确认
                Button myDelete = (Button)e.Row.FindControl("btnMyDelete");
                myDelete.Attributes.Add("onclick", "javascript:return confirm('确定删除吗?');");
            }
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvOrderLab_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvOrderLab.PageIndex = e.NewPageIndex;
            bindgvOrderLab();
        }

        /// <summary>
        /// 全选、反选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void chkHeader_CheckedChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow gr in gvOrderLab.Rows)
            {
                CheckBox chkItem = (CheckBox)gr.FindControl("chkItem");
                //相互变幻
                chkItem.Checked = !chkItem.Checked;
            }
        }


        /// <summary>
        /// 具体的删除数据行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnMyDelete_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow gr in gvOrderLab.Rows)
            {
                CheckBox chkItem = (CheckBox)gr.FindControl("chkItem");
                if (chkItem.Checked)
                {
                    //删除选中行数据
                    LMSDataContext.GetLMSDB.sp_delOrderlab(gr.Cells[2].Text.Trim());
                }
            }
            bindgvOrderLab();//再次绑定数据
        }


    }
}